//
//  WebViewController.m
//  MedicineBox
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "WebViewController.h"
#import "DKNightVersion.h"
@interface WebViewController ()<UIWebViewDelegate>

@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) UIView *backV;
@property (nonatomic, retain) UIWebView *webV;
@property (nonatomic, retain) UIActivityIndicatorView *activityI;

@end

@implementation WebViewController

-(void)dealloc{
    
    [_label release];
    [_backV release];
    [_activityI release];
    [_webV release];
    [_target release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.nightBackgroundColor = UIColorFromRGB(0x343434);
    
    if (_target.length == 0) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有更多数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [self.view addSubview:alert];
        [alert show];
        
    }  else  {
    
        
            [self createWeb];
            
      }

}



- (void)getSignal:(NSString *)my
{
    
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    navView.nightBackgroundColor = UIColorFromRGB(0x444444);
    navView.backgroundColor = [UIColor colorWithRed:86/255.0 green:137/255.0 blue:156/255.0 alpha:1];
    [self.view addSubview:navView];
    [navView release];
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 100) / 2 - 80, 30, 250, 30)];
   
    _label.textColor = [UIColor whiteColor];
    _label.textAlignment = NSTextAlignmentCenter;
    _label.nightTextColor = [UIColor whiteColor];
    [navView addSubview:_label];
    [_label release];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10 , 30, 60, 30)];
    [navView addSubview:button];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [button release];

    _label.text = my;
    
    _label.textColor = [UIColor whiteColor];
    _label.font = [UIFont fontWithName:@"Baskerville-SemiBold" size:20];

}
- (void)buttonAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)createWeb
{
    self.webV = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64)];
    _webV.delegate = self;
    _webV.nightBackgroundColor = UIColorFromRGB(0x343434);
    NSURL *url = [NSURL URLWithString:self.target];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [_webV loadRequest:request];
    
    [self.view addSubview:_webV];
    [_webV release];

}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{

    [_backV removeFromSuperview];
    [_activityI stopAnimating];

}

#warning 我的添加，数据加载框
- (void)webViewDidStartLoad:(UIWebView *)webView
{

    self.backV = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 50, self.view.frame.size.height / 2 - 50, 100, 100)];
    [self.view addSubview:_backV];
    [_backV release];
    self.backV.backgroundColor = [UIColor lightGrayColor];
    _backV.layer.cornerRadius = 10;
    
    UILabel *waitLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 70, _backV.frame.size.width, 20)];
    waitLabel.text = @"正在加载数据";
    waitLabel.textAlignment = NSTextAlignmentCenter;
    waitLabel.font = [UIFont systemFontOfSize:10];
    waitLabel.textColor = [UIColor whiteColor];
    [_backV addSubview:waitLabel];
    [waitLabel release];
    
    self.activityI = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(_backV.frame.size.width / 2 - 30, _backV.frame.size.height / 2 - 30, 60, 60)];
    _activityI.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    [_backV addSubview:_activityI];
    [_activityI startAnimating];
    [_activityI release];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
